import { ApiProperty } from '@midwayjs/swagger';
import { Rule, RuleType } from '@midwayjs/validate';
import { alternatives, StrIdValidator } from '..';
import { ArticleCategorySchema } from '../../schema';

export class SaveArticleCategoryValidator implements ArticleCategorySchema {
  @ApiProperty({
    type: 'string',
    title: '文章分类名称',
    example: 'null',
    description: '文章分类名称',
    required: true,
  })
  @Rule(RuleType.string().required())
  categoryName: string;

  @ApiProperty({
    type: 'string',
    title: '文章分类编码',
    example: 'null',
    description: '文章分类编码',
    required: true,
  })
  @Rule(RuleType.string().required())
  categoryCode: string;

  @ApiProperty({
    type: StrIdValidator,
    title: '文章分类父级',
    example: { id: '' },
    description: '文章分类父级',
    required: false,
  })
  @Rule(RuleType.alternatives(alternatives))
  parent?: ArticleCategorySchema;
}

export class EditArticleCategoryValidator
  implements Partial<ArticleCategorySchema>
{
  @ApiProperty({
    type: 'string',
    title: '文章分类名称',
    example: 'null',
    description: '文章分类名称',
    required: false,
  })
  @Rule(RuleType.alternatives(alternatives))
  categoryName?: string;

  @ApiProperty({
    type: 'string',
    title: '文章分类编码',
    example: 'null',
    description: '文章分类编码',
    required: false,
  })
  @Rule(RuleType.alternatives(alternatives))
  categoryCode?: string;

  @ApiProperty({
    type: StrIdValidator,
    title: '文章分类父级',
    example: { id: '' },
    description: '文章分类父级',
    required: false,
  })
  @Rule(RuleType.alternatives(alternatives))
  parent?: ArticleCategorySchema;
}
